import math

#$Id: sampseq.py 15 2006-04-11 23:22:57Z magee $
# -------------------------------------------------------------
#
__version__      = '$Revision: 15 $ '[11:-3]
__version_date__ = '$Date: 2006-04-11 23:22:57 +0000 (Tue, 11 Apr 2006) $ '[7:-3]
__author__       = 'R. Bouwens, <bouwens@ucolick.org>, D. Magee, <magee@ucolick.org>'

def NBeginReads(Samp_Seq):
  if Samp_Seq.startswith('SPARS'):
    NSamp = 3
  elif Samp_Seq.startswith('STEP'):
    Base = int(Samp_Seq[4:])
    NSamp = 3 + int(math.log10(Base)/math.log10(2)+0.5)
  return NSamp    

def TimeSeq(Samp_Seq,Samp):
  if Samp < 3:
    V = Samp * 0.303
  else:
    if Samp_Seq.startswith('SPARS'):
      Base = int(Samp_Seq[5:])
      V = Base * (Samp-2)
    elif Samp_Seq.startswith('STEP'):
      Base = int(Samp_Seq[4:])
      Samp -= 3
      V = 1
      while (Samp > 0) and (V < Base):
        V *= 2
        Samp -= 1
      while (Samp > 0):
        V += Base
        Samp -= 1
  return V

